﻿using System.IO.Ports;
using static Proxy.Utility;

namespace Proxy
{
    public class ManualScanner
    {
        private InsertInfoHandle Handle_Insert;
        private SearchInfoHandle Handle_Search;

        public ManualScanner(string comName, int baud)
        {
            Handle_Insert = new InsertInfoHandle();
            Handle_Search = new SearchInfoHandle();
            InitSerialPort(comName, baud);
        }

        public void InitSerialPort(string comName, int baud)
        {
            //var ManualScanner = SerialPortsHelper.OpenClosePort(comName, baud);
            //ManualScanner.DataReceived += ManualScanner_DataReceived;
        }

        private void ManualScanner_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (Globle.isRunEmptyActive)
            {
                HomagGroup.Base.UI.Windows.MessageBox.Show(GetLocalText("Run Empty function is running  loading function is disabled"));
                return;
            }

            SerialPort _SerialPort = (SerialPort)sender;

            int _bytesToRead = _SerialPort.BytesToRead;
            byte[] recvData = new byte[_bytesToRead];

            _SerialPort.Read(recvData, 0, recvData.Length);

            string Reference = System.Text.UTF8Encoding.UTF8.GetString(recvData).Replace('\r', ' ').Trim();

            if (string.IsNullOrWhiteSpace(Reference))
            {
                return;
            }
        }
    }
}